<?php
// +----------------------------------------------------------------------
// | SL 2018.8.17
// +----------------------------------------------------------------------
// | Copyright (c) 2018~2018 http://sl.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: zq <1040657944@qq.com>
// +----------------------------------------------------------------------

namespace app\model;


use think\Model;

class NoteModel extends Model
{
    // 确定链接表名
    protected $name = 'note';
    //开启时间戳写入
    protected $autoWriteTimestamp = true;

    /**
     * 插入新的帖子
     */
    public function insertNote($param)
    {
        try{
            $result =  $this->allowField(true)->validate('NoteValidate')->save($param);
            if(false === $result){
                // 验证失败 输出错误信息
                return msg(-1, '', $this->getError());
            }else{
                return msg(1, '/index/forum/index', '发表帖子成功!');
            }
        }catch(PDOException $e){

            return msg(-2, '', $e->getMessage());
        }
    }

    /**
     * 获取帖子列表
     * @return mixed
     */
    public function getNoteList($where)
    {
        return $this->where($where)->order("update_time desc")->select();
    }
}